package org.onvivals.app.modules.index;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.onvivals.app.modules.index.vo.IndexVo;
import org.onvivals.common.web.Result;
import org.onvivals.module.ums.entity.UmsNotice;
import org.onvivals.module.ums.service.ISysGroupDataService;
import org.onvivals.module.ums.service.IUmsNoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: Mr.ZS
 * @Date: 2024/10/28 下午2:42
 **/
@Slf4j
@RestController
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Tag(name = "小程序:首页")
@RequestMapping("/index")
public class IndexController {

	private final IUmsNoticeService umsNoticeService;

	private final ISysGroupDataService sysGroupDataService;

	@GetMapping
	@Operation(summary = "首页数据")
	public Result<IndexVo> index() {
		LambdaQueryWrapper<UmsNotice> umsNoticeLambdaQueryWrapper = Wrappers.<UmsNotice>lambdaQuery().orderByDesc(UmsNotice::getCreateBy);
		List<UmsNotice> umsNoticeList = umsNoticeService.list(umsNoticeLambdaQueryWrapper);
		IndexVo indexVo = IndexVo.builder()
				.notice(umsNoticeList)
				.banner(sysGroupDataService.getDatas("home_banner"))
				.build();
		return Result.OK(indexVo);
	}


	/**
	 * 政策协议
	 * @param type service=服务协议,privacy=隐私协议，vip=充值协议
	 * @return
	 */
	@GetMapping("/policy/{type}")
	@Operation(summary = "政策协议 service=服务协议,privacy=隐私协议，vip=充值协议")
	public Result<?> policy(@PathVariable String type) {
		log.info("type:{}", type);
		JSONObject data = sysGroupDataService.getData(type);
		return Result.OK(data);
	}

	/**
	 * 活动福利
	 */
	@GetMapping("/activity")
	@Operation(summary = "活动福利")
	public Result<?> activity() {
		JSONObject data = sysGroupDataService.getData("activity");
		return Result.OK(data);
	}

	/**
	 * 使用说明
	 */
	@GetMapping("/instructions")
	@Operation(summary = "使用说明")
	public Result<?> instructions() {
		JSONObject data = sysGroupDataService.getData("instructions");
		return Result.OK(data);
	}


}
